package com.cloudfast.config.property.c;

import java.io.File;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import lombok.Data;

@Data
@Component
@ConfigurationProperties(prefix = "cloudfast.storage.default")
public class DefaultProperty {
    private String host;
    private String port;
    private String fileHome;
    private String username;
    private String password;
    private boolean isWindows;

    private String browserPrefix;

    /**
     * 服务器文件存储路径
     *
     * @param filePath
     * @return
     */
    public String serverStoragePath(String filePath) {
        if (isWindows) {
            return filePath.replaceAll("//", "/");
        }
        String _filePath = (this.fileHome + "/" + filePath).replaceAll("//", "/");
        File file = new File(_filePath, "1.txt");
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        return _filePath.replace("//", "/");
    }
}
